/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:56 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{
    public class SlideDAL : SqlProvider<SlideEntity>
    {
        static SlideDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                SlideEntity entity = new SlideEntity();
                entity.PK_iSlideID = Int32.Parse("0" + dr["PK_iSlideID"].ToString());
                entity.sTenslide = dr["sTenslide"].ToString();
                entity.iTrangthai = int.Parse("0" + dr["iTrangthai"].ToString());
                entity.sVideo = dr["sVideo"].ToString();
                entity.sGhichu = dr["sGhichu"].ToString();
                entity.FK_iAnhminhhoaID = Int64.Parse("0" + dr["FK_iAnhminhhoaID"].ToString());
                entity.FK_iNguoitaoID = Int64.Parse("0" + dr["FK_iNguoitaoID"].ToString());
                entity.FK_iNguoicapnhatID = Int64.Parse("0" + dr["FK_iNguoicapnhat"].ToString());
                if (!dr["dThoidiemtao"].ToString().Trim().Equals(""))
                {
                    entity.dThoidiemtao = DateTime.Parse(dr["dThoidiemtao"].ToString());
                }
                else
                {
                    entity.dThoidiemtao = DateTime.Now;
                }
                if (!dr["dThoidiemcapnhat"].ToString().Trim().Equals(""))
                {
                    entity.dThoidiemcapnhat = DateTime.Parse(dr["dThoidiemcapnhat"].ToString());
                }
                else
                {
                    entity.dThoidiemcapnhat = DateTime.Now;
                }
                return entity;
            };
        }
        public static SlideEntity GetOne(Int64 PK_iSlideID)
        {
            string cmdName = "spSlide_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iSlideID", PK_iSlideID);
            SlideEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<SlideEntity> GetAll()
        {
            string cmdName = "spSlide_Get";
            return GetList(cmdName);
        }
        
        public static int Add(SlideEntity entity)
        {
            string cmdName = "spSlide_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(SlideEntity entity)
        {
            string cmdName = "spSlide_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iSlideID)
        {
            string cmdName = "spSlide_Delete";
            SqlParameter p = new SqlParameter("@PK_iSlideID", PK_iSlideID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(SlideEntity entity)
        {
            SqlParameter[] p = new SqlParameter[10];
			p[0] = new SqlParameter("@PK_iSlideID", entity.PK_iSlideID);
			p[1] = new SqlParameter("@sTenslide", entity.sTenslide);
			p[2] = new SqlParameter("@iTrangthai", entity.iTrangthai);
			p[3] = new SqlParameter("@sGhichu", entity.sGhichu);
            p[4] = new SqlParameter("@FK_iAnhminhhoaID", entity.FK_iAnhminhhoaID);
            p[5] = new SqlParameter("@FK_iNguoitaoID", entity.FK_iNguoitaoID);
            p[6] = new SqlParameter("@FK_iNguoicapnhatID", entity.FK_iNguoicapnhatID);
            p[7] = new SqlParameter("@dThoidiemtao", entity.dThoidiemtao);
            p[8] = new SqlParameter("@dThoidiemcapnhat", entity.dThoidiemcapnhat);
            p[9] = new SqlParameter("@sVideo", entity.sVideo);
            return p;
        }
        #endregion
       
    }
}